//
//  NINavigationController.m
//  gweAD
//
//  Created by navinfo air on 2016/11/23.
//  Copyright © 2016年 mengy. All rights reserved.
//

#import "NINavigationController.h"
#import "NITitleView.h"
#import "NIBaseViewController.h"

@interface NINavigationController ()

@end

@implementation NINavigationController
@synthesize titleView;

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadTitleView];

    // Do any additional setup after loading the view.
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - navigationBar

-(void)loadTitleView
{
    titleView = [[NITitleView alloc]initWithFrame:CGRectMake(0, 0, self.navigationBar.frame.size.width, self.navigationBar.frame.size.height)];
    
    [self.navigationBar addSubview:titleView];
    
    [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.top.bottom.mas_equalTo(self.navigationBar);
    }];
    
    [titleView setBackBtnWithImageName:@"login_return" action:@selector(onClickBackButton) target:self];
}


- (UIImage *)createImageWithColor:(UIColor *)color frame:(CGRect)rect

{
    
    UIGraphicsBeginImageContext(rect.size);
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    
    CGContextFillRect(context, rect);
    
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return theImage;
    
}

/**
 点击返回按钮
 */
-(void)onClickBackButton
{
    UIViewController *vc = [self topViewController];
    if ([vc isKindOfClass:[NIBaseViewController class]]) {
        NIBaseViewController *baseVC = (NIBaseViewController *)vc;
        [baseVC onClickBackButton];
    }
}

 //支持的方向
 - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
     return self.interfaceOrientationMask;
 }


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return self.interfaceOrientation;
}

@end
